#!/bin/bash
#description cut nginx log file
cat >> ./domain.txt <<EOF
one.com
two.com
EOF
Date=$(date +%F)
InstallDir="/data/application/nginx"
NginxLogDir="/data/log/nginx"
Dir="/root"
BackServer="10.2.11.241"
BackDir="/backup"
BackUser='www'
yum -y install rsync &>/dev/null
for domain in $(cat ./domain.txt);do
	cd ${NginxLogDir}/
	/bin/mv ${domain}_access.log ${domain}_access_${Date}.log
	tar zcf ${domain}_access_${Date}.tar.gz ${domain}_access_${Date}.log
	if [ $? -eq 0 ];then
		rm -rf ${domain}_access_${Date}.log
	fi
	systemctl reload nginx
	/usr/bin/rsync -az ${domain}_access_${Date}.tar.gz ${BackUser}@${BackServer}:${BackDir}
done
##Delete logs 7 days ago
find . -ctime +7 -name "*.log"|xargs rm -f

